﻿package mortal.game.view.achievement
{
    import Message.Public.*;
    import mortal.game.view.achievement.data.*;

    public class AchievementCache extends Object
    {
        private var _overViewArr:Array;
        private var _upComingArr:Array;
        public var typeArr:Array;
        public var typeObj:Object;
        public var catoryTypeObj:Object;
        public var showTipPanel:Boolean = false;
        public var categoryArr:Array;
        public var getTypeType:int = -1;
        public var getCatoryType:int = -1;
        public var canGetFlagArr:Array;
        private var _ordDic:Object;

        public function AchievementCache()
        {
            this.typeObj = {};
            this.catoryTypeObj = {};
            this.categoryArr = [];
            this.canGetFlagArr = [];
            this._ordDic = {3:100, 2:99, 5:98};
            this.genCategoryTabData();
            return;
        }// end function

        private function genCategoryTabData() : void
        {
            var _loc_2:AchievementCategoryNum = null;
            var _loc_1:int = 0;
            while (_loc_1 < 8)
            {
                
                _loc_2 = new AchievementCategoryNum();
                _loc_2.id = _loc_1;
                this.categoryArr.push(_loc_2);
                _loc_1++;
            }
            return;
        }// end function

        public function initOverViewData(param1:Array) : void
        {
            this._overViewArr = param1;
            this._overViewArr.sortOn(["category"], [Array.NUMERIC]);
            return;
        }// end function

        public function updateOverViewData(param1:SAchievementCategory) : void
        {
            var _loc_3:SAchievementCategory = null;
            if (this._overViewArr == null)
            {
                return;
            }
            var _loc_2:int = 0;
            while (_loc_2 < this._overViewArr.length)
            {
                
                _loc_3 = this._overViewArr[_loc_2];
                if (_loc_3.category == param1.category)
                {
                    this._overViewArr[_loc_2] = param1;
                    break;
                }
                _loc_2++;
            }
            return;
        }// end function

        public function updateCanGetFlagArr(param1:Array) : void
        {
            this.canGetFlagArr = param1;
            return;
        }// end function

        public function initTypeData(param1:Array) : void
        {
            var _loc_3:Array = null;
            var _loc_4:SAchievementType = null;
            this.catoryTypeObj = {};
            this.typeArr = param1;
            this.typeArr.sortOn(["category", "type"], [Array.NUMERIC, Array.NUMERIC]);
            var _loc_2:int = 0;
            while (_loc_2 < param1.length)
            {
                
                _loc_4 = param1[_loc_2];
                if (this.catoryTypeObj[_loc_4.category] == null)
                {
                    this.catoryTypeObj[_loc_4.category] = [];
                }
                this.catoryTypeObj[_loc_4.category].push(_loc_4);
                _loc_2++;
            }
            for each (_loc_3 in this.catoryTypeObj)
            {
                
                _loc_3.sort(this.sortStatus);
            }
            return;
        }// end function

        private function sortStatus(param1:SAchievementType, param2:SAchievementType) : int
        {
            var _loc_3:* = int(this._ordDic[param1.status]);
            var _loc_4:* = int(this._ordDic[param2.status]);
            if (_loc_3 > _loc_4)
            {
                return -1;
            }
            if (_loc_3 < _loc_4)
            {
                return 1;
            }
            return 0;
        }// end function

        public function updateTypeData(param1:SAchievementType) : void
        {
            var _loc_4:SAchievementType = null;
            if (this.catoryTypeObj[param1.category] == null)
            {
                this.catoryTypeObj[param1.category] = [];
            }
            var _loc_2:* = this.catoryTypeObj[param1.category];
            var _loc_3:int = 0;
            while (_loc_3 < _loc_2.length)
            {
                
                _loc_4 = _loc_2[_loc_3];
                if (_loc_4.type == param1.type)
                {
                    _loc_2[_loc_3] = param1;
                    break;
                }
                _loc_3++;
            }
            _loc_2.sort(this.sortStatus);
            return;
        }// end function

        public function addTypeData(param1:SAchievementType) : void
        {
            if (this.catoryTypeObj[param1.category] == null)
            {
                this.catoryTypeObj[param1.category] = [];
            }
            var _loc_2:* = this.catoryTypeObj[param1.category];
            _loc_2.push(param1);
            _loc_2.sort(this.sortStatus);
            return;
        }// end function

        public function addNewTypeData(param1:SAchievementType) : void
        {
            var _loc_3:int = 0;
            var _loc_4:SAchievementType = null;
            var _loc_2:* = this.catoryTypeObj[param1.category];
            if (_loc_2)
            {
                _loc_3 = 0;
                while (_loc_3 < _loc_2.length)
                {
                    
                    _loc_4 = _loc_2[_loc_3];
                    if (_loc_4.type == param1.type)
                    {
                        _loc_2[_loc_3] = param1;
                        break;
                    }
                    _loc_3++;
                }
                _loc_2.sort(this.sortStatus);
            }
            return;
        }// end function

        public function checkHasReward(param1:Object) : Boolean
        {
            var _loc_2:int = 0;
            if (param1 && param1["status"])
            {
                _loc_2 = param1["status"];
                if (EAchieveStatus._EAchieveStatusCompelete == _loc_2)
                {
                    return true;
                }
            }
            return false;
        }// end function

        public function get overViewArr() : Array
        {
            return this._overViewArr;
        }// end function

        public function set overViewArr(param1:Array) : void
        {
            this._overViewArr = param1;
            return;
        }// end function

        public function get upComingArr() : Array
        {
            return this._upComingArr;
        }// end function

        public function set upComingArr(param1:Array) : void
        {
            this._upComingArr = param1;
            return;
        }// end function

    }
}
